package model

import (
	"fmt"
)

// User 用户表
type Sinfos struct {
	Id        int    `json:"id" form:"id"`
	Sno       string `json:"sno" form:"sno"`
	Sname     string `json:"sname" form:"sname"`
	Simg      string `json:"simg" form:"simg"`
	Info      string `json:"info" form:"info"`
	Cid       string `json:"cid" form:"cid"`
	Sex       string `json:"sex" form:"sex"`
	Age       int    `json:"age" form:"age"`
	Birth     string `json:"birth" form:"birth"`
	Tel       string `json:"tel" form:"tel"`
	Hobby     string `json:"hobby" form:"hobby"`
	Infocount int    `json:"infocount" form:"infocount"`
}

func SinfosAll(cid string) ([]Sinfos, error) {
	mods := make([]Sinfos, 0, 4)
	err := DB.Select(&mods, "select * from sinfo where cid=?", cid)
	return mods, err
}
func SinfosOne(sno string) (s Sinfos, sname, sex, tel string, infocount int, err error) {
	mods := make([]Sinfos, 0, 1)
	err = DB.Select(&mods, "select * from sinfo where sno=?", sno)
	sname = mods[0].Sname
	tel = mods[0].Tel
	sex = mods[0].Sex
	infocount = mods[0].Infocount
	fmt.Println(sex)

	return mods[0], sname, sex, tel, infocount, err
}
func Sinfoupdate(hobby, tel, info, sno string) bool {
	// UPDATE Person SET FirstName = 'Fred' WHERE LastName = 'Wilson'
	result, _ := DB.Exec("UPDATE `sinfo` set `hobby`=?,`tel`=?,`info`=? where sno=?", hobby, tel, info, sno)

	affect, _ := result.RowsAffected()
	if affect == 1 {
		return true
	}
	return false
}
